﻿#ifndef HNRJITWIDGET_H
#define HNRJITWIDGET_H

#include <atlcoll.h> // ATL集合
#include <atlstr.h> // ATL字符串
#include <atltypes.h> // ATL类型

#include <commctrl.h>
#include <imaging.h>

#include "../TinyXml2/unzip.h"
#include "../TinyXml2/tinyxml2.h"

#include "DirectUIGlobal.h"

class CHnrjitControl;
class CHnrjitContainer;

#define TiXmlElement XMLElement
#define TiXmlDocument XMLDocument

// 所有控件或容器父类
class DIRECTUI_API CHnrjitWigdet
{
public:
	explicit CHnrjitWigdet();
	virtual ~CHnrjitWigdet();

	/// <summary>获取当前类标识</summary>
	virtual DWORD GetClsid() const { return CLSID_HNRJITWIDGET; }

	/// <summary>是否属于指定类型</summary>
	/// <param name="dwClsid">指定类型</param>
	/// <returns>是或否</returns>
	BOOL IsKindOf(DWORD dwClsid) const { return GetClsid() == dwClsid; }

	/// <summary>设置属性值</summary>
	/// <param name="pxElement">XML元素</param>
	/// <param name="hZipRes">ZIP句柄</param>
	virtual void SetAttribute(const TiXmlElement* pxElement, HZIP hZipRes = NULL);

public:
	/// <summary>控件唯一标识属性</summary>
	virtual DWORD GetCtrlid() const;
	virtual void SetCtrlid(DWORD dwCtrlid);

	/// <summary>控件名称属性</summary>
	virtual const CAtlString& GetName() const;
	virtual void SetName(const TCHAR* pszName);

	/// <summary>控件位置属性</summary>
	virtual CPoint GetLocation() const;
	virtual void SetLocation(const CPoint& ptLocation);
	virtual void SetLocation(int nX, int nY);

	/// <summary>控件大小属性</summary>
	virtual CSize GetSize() const;
	virtual void SetSize(const CSize& tagSize);
	virtual void SetSize(int nWidth, int nHeight);

	/// <summary>控件区域属性</summary>
	virtual const CRect& GetGeometry() const;
	virtual void SetGeometry(CPoint ptLocation, CSize tagSize);
	virtual void SetGeometry(int nX, int nY, int nWidth, int nHeight);

	/// <summary>控件是否可用属性</summary>
	virtual BOOL IsEnabled() const;
	virtual void SetEnabled(BOOL isEnabled);

	/// <summary>控件是否可见属性</summary>
	virtual BOOL IsVisible() const;
	virtual void SetVisible(BOOL isVisible);

	/// <summary>控件是否透明属性</summary>
	virtual BOOL IsTransparent() const;
	virtual void SetTransparent(BOOL isTransparent);

public:
	/// <summary>键盘按下事件</summary>
	/// <param name="nChar">虚拟键码</param>
	/// <param name="nRepCnt">重复次数</param>
	/// <param name="nFlags">扫描代码</param>
	virtual void OnKeyPress(UINT nChar, UINT nRepCnt, UINT nFlags) {};

	/// <summary>键盘释放事件</summary>
	/// <param name="nChar">虚拟键码</param>
	/// <param name="nRepCnt">重复次数</param>
	/// <param name="nFlags">扫描代码</param>
	virtual void OnKeyRelease(UINT nChar, UINT nRepCnt, UINT nFlags) {};

	/// <summary>鼠标按下事件</summary>
	/// <param name="nFlags">按下的键</param>
	/// <param name="point">鼠标位置</param>
	virtual void OnMousePress(UINT nFlags, CPoint point) {};

	/// <summary>鼠标释放事件</summary>
	/// <param name="nFlags">按下的键</param>
	/// <param name="point">鼠标位置</param>
	virtual void OnMouseRelease(UINT nFlags, CPoint point) {};

	/// <summary>鼠标移动事件</summary>
	/// <param name="nFlags">按下的键</param>
	/// <param name="point">鼠标位置</param>
	virtual void OnMouseMove(UINT nFlags, CPoint point) {};

protected:
	/// <summary>绘制窗口</summary>
	/// <param name="rcRect">要绘制区域</param>
	virtual void Invalidate(const CRect& rcRect) = 0;

protected:
	DWORD m_dwCtrlid; // 控件唯一标识

	CAtlString m_strName; // 控件名称

	CRect m_rcGeometry; // 控件可视区域

	BOOL m_isEnabled; // 控件是否可用

	BOOL m_isVisible; // 控件是否可见

	BOOL m_isTransparent; // 控件是否透明

#ifdef _DEBUG
	DWORD m_dwThreadID; // 当前线程标识（确保控件从创建到销毁及每次更改均在同一个线程内完成）
#endif // _DEBUG
};

#endif // HNRJITWIDGET_H